{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "GRFGQA"

// By ArtemQa146

const
    gang_man = 31@
    gang_check = 30@
    spray_fx = 29@

    Event = 27@
    coords_x = 26@
    coords_y = 25@
    coords_z = 24@
    angle_1 = 23@
    obj_1 = 21@
    obj_2 = 20@
    render_1 = 19@
    render_11 = 18@
    render_2 = 17@
    render_22 = 16@
    render_3 = 15@
    render_33 = 14@
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)
0085: gang_check = 4@ // (int)

if
    0E4D: random_percent 5@
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end

repeat
wait 0
04ED: load_animation  "PedEventsMod"
until 04EE:   animation "PedEventsMod" loaded




if
    gang_check == 7
then
    0209: 2@ = random_int_in_ranges 1 4
    if 2@ == 1
    then 1@ = 102
    end
    if 2@ == 2
    then 1@ = 103
    end
    if 2@ == 3
    then 1@ = 104
    end
end

if
    gang_check == 8
then
    0209: 2@ = random_int_in_ranges 1 4
    if 2@ == 1
    then 1@ = 105
    end
    if 2@ == 2
    then 1@ = 106
    end
    if 2@ == 3
    then 1@ = 107
    end
end

if
    gang_check == 9
then
    0209: 2@ = random_int_in_ranges 1 4
    if 2@ == 1
    then 1@ = 108
    end
    if 2@ == 2
    then 1@ = 109
    end
    if 2@ == 3
    then 1@ = 110
    end
end

model.Load(1@)
model.Load(3000)
model.Load(365)
if
    not model.Available(1@)
then
    repeat
    wait 0
    model.Load(1@)
    until model.Available(1@)
end
if
    not model.Available(3000)
then
    repeat
    wait 0
    model.Load(3000)
    until model.Available(3000)
end
if
    not model.Available(365)
then
    repeat
    wait 0
    model.Load(365)
    until model.Available(365)
end
038B: load_requested_models
009A: gang_man = create_actor_pedtype gang_check model 1@ at coords_x coords_y coords_z
0173: set_actor gang_man Z_angle_to angle_1
0E24: fix_char gang_man ground 1 brightness 1 and_fade_in 0
0812: AS_actor gang_man perform_animation "grf_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
Event = 0
model.Destroy(1@)
04C4: store_coords_to 1@ 2@ 3@ from_actor gang_man with_offset 0.0 1.0 0.0
0E01: create_object_no_save 3000 at 1@ 2@ 3@ offset 0 ground 0 to obj_1
08D2: object obj_1 scale_model 0.0
0382: set_object obj_1 collision_detection 0
07F7: set_object obj_1 destructible 0
0E01: create_object_no_save 3000 at 1@ 2@ 3@ offset 0 ground 0 to obj_2
08D2: object obj_2 scale_model 0.0
0382: set_object obj_2 collision_detection 0
07F7: set_object obj_2 destructible 0
angle_1 += 90.0
0177: set_object obj_1 Z_angle_to angle_1
0177: set_object obj_2 Z_angle_to angle_1
model.Destroy(3000)
if
    gang_check == 7
then 
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqab1"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_1
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_11
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqab2"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_2
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_22
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqab3"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_3
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_33
end
if
    gang_check == 8
then
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqa1"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_1
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_11
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqa2"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_2
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_22
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqa3"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_3
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_33
end
if
    gang_check == 9
then
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqav1"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_1
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_11
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqav2"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_2
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_22
    0AF0: 2@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "tagqav3"
    0F04: create_render_object_to_object_from_special obj_1 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_3
    0F04: create_render_object_to_object_from_special obj_2 special_model 2@ offset 0.0 0.0 0.0 rotation 0.0 0.0 0.0 store_to render_33
end

0E2E: create_render_object_to_char_bone gang_man model 365 bone 24 offset 0 0 0 rotation 0 0 0 store_to 1@
0E30: set_render_object_auto_hide 1@ dead 1 weapon 1 car 1
model.Destroy(365)

064B: spray_fx = create_particle "extinguisher" at 0.0 0.0 0.0 type 1
064C: make_particle spray_fx visible


0E31: set_render_object_visible render_2 0
0E31: set_render_object_visible render_22 0
0E31: set_render_object_visible render_3 0
0E31: set_render_object_visible render_33 0
timerb = 0
Event = 0

wait 300

repeat
wait 0
    if
        056D:   actor gang_man defined
    then

        // , ,    
        080E: get_actor $PLAYER_ACTOR ped_event_to 2@
        080E: get_actor gang_man ped_event_to 3@
        if or
            actor.Dead(gang_man)
            2@ == 11
            3@ == 49
            3@ == 9
            051A:   actor gang_man damaged_by_actor $PLAYER_ACTOR
            not is_char_script_controlled gang_man
            not locate_char_distance_to_coordinates gang_man pos coords_x coords_y coords_z radius 3.0
        then
            break
        end
        
        080E: get_actor gang_man ped_event_to 2@
        if or
            2@ == 15
            2@ == 31
            2@ == 59
        then
            break
        end
        
        if
            not $ACTIVE_INTERIOR == 0
        then
            break
        end

        //    
        if
            0457:   player $PLAYER_CHAR aiming_at_actor gang_man
        then
            0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
            0E89: get_weaponinfo_fire_type 2@ store_to 3@ //     
            if or
                3@ == 1 //  
                3@ == 3 //   (  ..)
            then
                break
            end
        end
        
    if
        0EE4: locate_char_distance_to_char $PLAYER_ACTOR char gang_man radius 25.0
    then

        if and
            timerb > 2000
            not Event == 2
        then
            if and
                8611:   not actor gang_man performing_animation "grf_idle"
                8611:   not actor gang_man performing_animation "grf_look"
                8611:   not actor gang_man performing_animation "grf_spray"
            then
                0812: AS_actor gang_man perform_animation "grf_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                timerb = 0
                wait 300
                continue
            end
        end

        if
            0611:   actor gang_man performing_animation "grf_idle"
        then
            0613: 1@ = actor gang_man animation "grf_idle" time
            if
                1@ > 0.9
            then
                if
                    Event == 2
                then
                    0812: AS_actor gang_man perform_animation "grf_look" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                else
                    0812: AS_actor gang_man perform_animation "grf_spray" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                end
                wait 300
                timera = 0
                continue
            end
        end
        
        if
            0611:   actor gang_man performing_animation "grf_spray"
        then
            0613: 1@ = actor gang_man animation "grf_spray" time
            if and
                timera > 5000
                1@ > 0.9
            then
                if
                    Event == 2
                then
                    0812: AS_actor gang_man perform_animation "grf_look" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                else
                    0812: AS_actor gang_man perform_animation "grf_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                end
                wait 300
                continue
            end
            0D0B: get_actor gang_man bone 24 matrix_pointer_to 1@ // IF and SET
            0D0A: store_coords_to 4@ 5@ 6@ from_matrix 1@ with_offsets 0.0 0.0 0.0
            if gang_check == 7
            then 0EC0: add_fx_system_particle spray_fx coord 4@ 5@ 6@ vel 0.0 0.0 0.0 size 1.0 brightness 1.0 rgba 0.5 0.0 0.7 0.35 lastFactor 1.0
            end
            if gang_check == 8
            then 0EC0: add_fx_system_particle spray_fx coord 4@ 5@ 6@ vel 0.0 0.0 0.0 size 1.0 brightness 1.0 rgba 0.2 1.0 0.2 0.35 lastFactor 1.0
            end
            if gang_check == 9
            then 0EC0: add_fx_system_particle spray_fx coord 4@ 5@ 6@ vel 0.0 0.0 0.0 size 1.0 brightness 1.0 rgba 0.8 0.4 0.1 0.35 lastFactor 1.0
            end
            if
                timerb > 25000
            then
                if
                    Event == 0
                then
                    0E31: set_render_object_visible render_1 0
                    0E31: set_render_object_visible render_11 0
                    0E31: set_render_object_visible render_2 1
                    0E31: set_render_object_visible render_22 1
                    Event = 1
                    timerb = 0
                    continue
                end
                if
                    Event == 1
                then
                    0E31: set_render_object_visible render_2 0
                    0E31: set_render_object_visible render_22 0
                    0E31: set_render_object_visible render_3 1
                    0E31: set_render_object_visible render_33 1
                    Event = 2
                    timerb = 0
                    continue
                end
            end
        end
        
        if
            0611:   actor gang_man performing_animation "grf_look"
        then
            0613: 1@ = actor gang_man animation "grf_look" time
            if
                1@ > 0.9
            then
                if
                    Event == 2
                then
                    break
                    0687: clear_actor gang_man task
                end
                wait 300
                continue
            end
        end
    else
        timerb = 0
    end

    else
        break
    end
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 120.0
04EF: release_animation "PedEventsMod"

if
    0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 50.0
then
    if 056D:   actor gang_man defined
    then 01C2: remove_references_to_actor gang_man // Like turning an actor into a random pedestrian
    end
    if 03CA:   object obj_1 exists
    then 01C4: remove_references_to_object obj_1 // This object will now disappear when the player looks away
    end
    if 03CA:   object obj_2 exists
    then 01C4: remove_references_to_object obj_2 // This object will now disappear when the player looks away
    end
else
    if 056D:   actor gang_man defined
    then 009B: destroy_actor gang_man
    end
    if 03CA:   object obj_1 exists
    then 0108: destroy_object obj_1
    end
    if 03CA:   object obj_2 exists
    then 0108: destroy_object obj_2
    end
end

0650: destroy_particle spray_fx

repeat
wait 0
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

0A93: terminate_this_custom_script

